<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>添加</title>
    <link rel="stylesheet" type="text/css" href="https://www.layuicdn.com/layui-v2.6.8/css/layui.css"/>
    <script src="https://www.layuicdn.com/layui-v2.6.8/layui.js"></script>
    <script src="https://www.layuicdn.com/laydate-v5.3.1/laydate.js"></script>
</head>
<style>
    body{
        padding: 20px 100px 20px 20px;
    }
</style>
<body>
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">地区</label>
        <div class="layui-input-block">
            <select name="areaId" lay-verify="required">
                <option value="">请选择</option>
                <!--后台传的值的命名为area  调值直接用area点-->
                <option th:each="area:${areaList}" th:value="${area.id}">
                    <span th:text="${area.areaName}"></span>
                </option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">人数</label>
        <div class="layui-input-block">
            <input type="text" name="infectedNum" required  lay-verify="required|number" placeholder="请输入感染人数" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">录入人</label>
        <div class="layui-input-block">
            <input type="text" name="enteredBy" required lay-verify="required" placeholder="请填写真实姓名" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">录入时间</label>
        <div class="layui-input-block">
            <input type="text" id="entryTime" name="entryTime" placeholder="录入时间" autocomplete="off"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block" style="float: right">
            <button id="btn-submit" class="layui-btn" lay-submit lay-filter="btn-submit">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>
<script>
    layui.use(['laydate', 'table', 'form'], function () {
        var laydate = layui.laydate;
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        /*日期控件设置*/
        laydate.render({
           elem: '#entryTime'
            ,value: new Date()
            ,type: 'datetime' //指定日期格式为 日月年 时分秒
        });

        /*表单提交事件*/
        form.on('submit(btn-submit)', function(data){
            //将登录按钮不可用
            $("#btn-submit").attr("disabled","disabled").addClass("layui-btn-disabled");
            //异步请求提交数据  第一个请求地址 第二个表单要提交的数据
                $.post("addInf", data.field, function (response) {
                    if (response.code == 0){
                        //成功提示
                        layer.msg(response.message, {
                            icon: 1,
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        }, function(){
                            //刷新表格
                            parent.refreshTable();
                            //关闭窗口
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                        });
                    }else {
                        //将登录取消不可用
                        $("#btn-submit").removeAttr("disabled","disabled").removeClass("layui-btn-disabled");
                        //失败提示
                        layer.msg("新增失败", {
                            icon: 2,
                            anim: 6
                        })
                    }
                });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

    });
</script>
</html>